package cn.szsys.integration.config;

import cn.szsys.integration.config.filter.EncryptionFilter;
import cn.szsys.integration.repository.AccessorRepository;
import jakarta.annotation.Resource;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Ryan
 * @since 2025-05-08
 **/
@Configuration
public class FilterConfig {
    @Resource
    private AccessorRepository accessorRepository;

    /**
     * 过滤器配置
     *
     * @return {@link FilterRegistrationBean <EncryptionFilter>}
     * @author Ryan
     */
    @Bean
    public FilterRegistrationBean<EncryptionFilter> encryptionFilter() {
        FilterRegistrationBean<EncryptionFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new EncryptionFilter(accessorRepository));
        // 设置过滤器应用的URL模式
        registrationBean.addUrlPatterns("/*");
        // 设置过滤器的顺序
        registrationBean.setOrder(1);
        return registrationBean;
    }

}
